<template>
  <div class="grey_bg">
    <navigate>
      预约记录详情
      <template #right>
        <div @click="deleteOperate()">删除</div>
      </template>
    </navigate>
    <div class="main_content">
      <div class="card">
        <img :src="joinUrlImg(counselorInfo.avatar)" alt class="avatar" />
        <div class="name_label">
          <div class="name">
            <div class="name_nick text_ellipsis">{{ counselorInfo.name }}</div>
            <div class="name_age">({{ counselorInfo.age }}岁)</div>
          </div>
          <div class="label flex_row">
            <div class="text nowrap">标签:</div>
            <div
              class="icon"
              v-for="(item, index) in counselorInfo.userTag"
              :key="index"
            >
              <img :src="joinUrlImg(item.tag_icon)" alt />
            </div>
          </div>
        </div>
        <div class="status" @click="lookDetail()">
          {{ "查看详情>>" }}
        </div>
      </div>

      <div class="start_block start_appointment">
        <div class="inner_title">
          <img class="deraction_img" src="@/assets/images/common/bar.png" alt />
          <div>发起预约情况</div>
        </div>

        <div class="user_info">
          <div class="info_item width_6 info_label border_right border_bottom">
            预约问题类型：
          </div>
          <div class="info_item width_7 info_ctt border_bottom">
            {{ info.question_name }}
          </div>
          <div class="info_item width_6 info_label border_right border_bottom">
            预约发起时间:
          </div>
          <div class="info_item width_7 info_ctt border_bottom">
            {{ convertTimestampToDateTime(info.time) }}
          </div>
          <div class="info_item width_6 info_label border_right border_bottom">
            预约人情况：
          </div>
          <div class="info_item width_7 info_ctt border_bottom">
            {{ info.type == 1 ? "本人预约" : "他人预约" }}
          </div>
          <div class="info_item width_6 info_label border_right">
            事项是否完结：
          </div>
          <div class="info_item width_7 info_ctt">
            {{ info.is_end ? "是" : "否" }}
          </div>
        </div>
      </div>

      <div class="inner_title">
        <img class="deraction_img" src="@/assets/images/common/bar.png" alt />
        <div>发起预约情况</div>
      </div>

      <div class="start_block">
        <div class="start_item bottom_line">
          <div class="start_label">具体预约时段：</div>
          <div class="start_ctt appointment_ctt">
            <div class="appointment_date">
              {{
                info.reservation_time ? info.reservation_time.split(" ")[0] : ""
              }}
            </div>
            <div class="appointment_time">
              {{
                info.reservation_time ? info.reservation_time.split(" ")[1] : ""
              }}
            </div>
          </div>
        </div>
        <div class="start_item">
          <div class="start_label">线下咨询地点：</div>
          <div class="start_ctt">{{ info.address }}</div>
        </div>
      </div>

      <div class="inner_title">
        <img class="deraction_img" src="@/assets/images/common/bar.png" alt />
        <div>预约问题描述</div>
      </div>

      <div class="block_ctt">
        {{ info.question }}
      </div>

      <div class="inner_title">
        <img class="deraction_img" src="@/assets/images/common/bar.png" alt />
        <div>咨询师回复</div>
      </div>

      <div class="block_ctt">
        {{ info.consult_reply || "暂无回复" }}
      </div>

      <div
        class="inner_title"
        v-if="
          info.zp_task &&
          info.cp_task &&
          info.cp_task.length != 0 &&
          info.zp_task.length != 0
        "
      >
        <img class="deraction_img" src="@/assets/images/common/bar.png" alt />
        <div>赴约前置任务</div>
      </div>

      <div class="task_list">
        <div class="block_item" v-for="(r, i) in info.cp_task" :key="i">
          <img class="row_img" :src="joinUrlImg(r.task_icon_url)" alt="" />
          <div class="row_middle">
            <div class="row_name">{{ r.task_name }}</div>
            <div :class="['row_status', { done_over: r.is_over_scale != 1 }]">
              <template v-if="r.is_over_scale == 1">
                <img src="@/assets/images/consult/success_1.png" alt="" />
                <div>已完成</div>
              </template>
              <template v-else>
                <div>完成状态：</div>
                <div>未完成</div>
              </template>
            </div>
          </div>
          <button
            class="btn row_btn"
            @click="lookResult(r)"
            :disabled="r.is_look == 0"
            :class="{ is_disabled: r.is_look == 0 }"
            v-if="r.is_over_scale == 1"
          >
            查看结果
          </button>
          <button
            @click="enterEvaluate(r)"
            class="btn row_btn"
            v-if="r.is_over_scale != 1"
          >
            进入测评
          </button>
        </div>
      </div>

      <div class="block_item" v-for="(r, i) in info.zp_task" :key="i">
        <img class="row_img" src="@/assets/images/consult/self.png" alt />
        <div class="row_middle">
          <div class="row_name">个人近况自评表</div>

          <div
            :class="[
              'row_status',
              { done_over: r.is_over_self_assessment == 0 },
            ]"
          >
            <template v-if="r.is_over_self_assessment != 0">
              <img src="@/assets/images/consult/success_1.png" alt="" />
              <div>已完成</div>
            </template>
            <template v-else>
              <div>完成状态：</div>
              <div>未完成</div>
            </template>
          </div>
        </div>
        <button
          class="btn row_btn"
          @click="fill(r)"
          v-if="r.is_over_self_assessment != 0"
        >
          答题情况
        </button>
        <button v-else class="btn row_btn" @click="fill(r)">开始填写</button>
      </div>
    </div>
  </div>
</template>

<script>
import { queryOfflineConsultInfo } from "@/api/consultation/offline.js";
import {
  queryOffConRecordDet,
  delOffConRecord,
} from "@/api/consultation/record";

import { convertTimestampToDateTime } from "@/utils/time";
import { joinUrlImg } from "@/utils/setUrlImg";
export default {
  data() {
    return {
      info: {},
      counselorInfo: {},
    };
  },
  created() {
    this.getOffConRecordDet();
  },
  methods: {
    joinUrlImg,
    convertTimestampToDateTime,
    // 详情
    async getOffConRecordDet() {
      let res = await queryOffConRecordDet({ id: this.$route.query.id });
      if (res.code == 200) {
        this.info = res.data;
        this.getUserInfo(res.data.consult_id);
      }
    },
    async getUserInfo(id) {
      let res = await queryOfflineConsultInfo({ id });
      if (res.code == 200) {
        this.counselorInfo = res.data;
      }
    },
    //删除
    deleteOperate() {
      this.$popup({
        title: "提示",
        message: `<div>确定要删除本条记录吗？</div>`,
        confirmOperate: async () => {
          let res = await delOffConRecord({
            id: this.info.id,
          });
          if (res.code == 200) {
            this.$toast.success("删除成功!");
            this.$router.go(-1);
          }
        },
      });
    },
    // 查看详情
    lookDetail() {
      this.$router.push(`/consultantInfo?id=${this.info.consult_id}`);
    },

    // 查看结果
    lookResult(r) {
      this.$router.push(
        `/testResult/${r.is_look == 0 ? 2 : 1}/${r.report_id || 0}`
      );
    },
    // 进入测评
    enterEvaluate(r) {
      this.$router.push(
        `/normalAnswer/${r.cp_rating_scale_id}/${r.cp_task_id}/0/0`
      );
    },
    // 开始填写
    fill(item) {
      this.$router.push(
        `/selfAssessment/${item.is_over_self_assessment == 0 ? 1 : 2}/${
          item.id || 0
        }`
      );
    },
  },
};
</script>

<style scoped>
.grey_bg {
  background: #f4f6fa;
  overflow-y: hidden !important;
}
.inner_title {
  height: 24.31px;
  font-size: 15.97px;
  font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  font-weight: bold;
  text-align: left;
  color: #333333;
  display: flex;
  align-items: center;
  gap: 10.42px;
  margin: 1.73px 0;
}
.deraction_img {
  height: 15.97px;
}
.bottom_line {
  position: relative;
}
.bottom_line::before {
  display: block;
  width: 100%;
  height: 0.35px;
  background: #dddddd;
  position: absolute;
  bottom: 0;
  left: 0;
  content: "";
}

.card {
  width: 354.17px;
  height: 83.33px;
  background: #ffffff;
  border-radius: 6.94px;
  margin: 10px auto 6px;
  padding: 10px;
  display: flex;
}
.card > img {
  width: 62.5px;
  height: 62.5px;
  margin-right: 13px;
  border-radius: 10px;
}
.name_label .name {
  height: 27.77px;
  line-height: 27.77px;
  font-size: 17.36px;
  font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  font-weight: bold;
  color: #333333;
  margin-bottom: 8.68px;
  display: flex;
}
.name_nick {
  max-width: 87px;
}
.text_ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.name_label .label {
  display: flex;
  align-items: center;
  gap: 3.47px;
}
.name_label .label .text {
  height: 22.57px;
  line-height: 22.57px;
  font-size: 14.58px;
  font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  font-weight: 400;
  color: #777777;
  margin-right: 3.82px;
}
.name_label .label .icon img {
  width: 22.57px;
  height: 22.57px;
}
.status {
  font-size: 14.58px;
  font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  font-weight: 400;
  text-align: left;
  margin-left: auto;
  color: #aaaaaa;
}
.user_info {
  width: 340.28px;
  height: fit-content;
  border: 0.35px solid #cccccc;
  border-radius: 3.47px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 112.15px auto;
  box-sizing: border-box;
}
.border_right {
  border-right: 0.35px solid #cccccc;
}
.border_bottom {
  border-bottom: 0.35px solid #cccccc;
}
.info_item {
  line-height: 24.3px;
  font-size: 13.89px;
  font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  font-weight: 400;
  box-sizing: border-box;
  padding: 5.21px 10.42px;
}
.info_label {
  text-align: justify;
  word-break: keep-all;
  color: #666666;
}
.info_ctt {
  color: #333333;
  word-break: break-all;
}
.main_content > .inner_title {
  margin-left: 6.94px;
}
.start_block {
  width: 100%;
  height: max-content;
  background: #ffffff;
  border-radius: 6.94px;
  box-sizing: border-box;
  padding: 0 6.94px;
  box-sizing: border-box;
  font-size: 14.58px;
  font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  font-weight: 400;
  color: #666666;
}
.start_appointment {
  padding-top: 12.15px;
  padding-bottom: 13.89px;
}
.start_block .inner_title {
  margin-bottom: 12.15px;
}
.start_item {
  display: grid;
  grid-template-columns: 92.01px auto;
  gap: 15.63px;
  padding: 12.15px 10.42px;
  box-sizing: border-box;
  line-height: 24.32px;
}
.start_label {
  color: #666666;
  text-align: justify;
  word-break: keep-all;
}
.start_ctt {
  text-align: justify;
  word-break: break-all;
}
.appointment_ctt {
  display: flex;
  gap: 3.47px;
  color: #333333;
}
.appointment_ctt div {
  width: 97.22px;
  height: 24.31px;
  border-radius: 3.47px;
  text-align: center;
}
.appointment_date {
  color: #ffffff;
  background: linear-gradient(0deg, #ffffff 0%, rgba(255, 255, 255, 0) 10%),
    #29cca6;
}
.appointment_time {
  color: #ffffff;
  background: linear-gradient(0deg, #ffffff 0%, rgba(255, 255, 255, 0) 10%),
    #ff9500;
}
.block_ctt {
  width: 354.17px;
  height: max-content;
  background: #ffffff;
  border-radius: 6.94px;
  line-height: 29.17px;
  padding: 9.375px 14.93px 17.015px 13.89px;
  box-sizing: border-box;
  font-size: 14.58px;
  font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  font-weight: 400;
  color: #333333;
  line-height: 29.17px;
  word-break: break-all;
}
.task_list {
  display: grid;
  gap: 10.42px;
}
.block_item {
  width: 100%;
  height: 104.17px;
  background: #ffffff;
  border-radius: 6.94px;
  box-sizing: border-box;
  padding: 0 10.42px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
}
.main_content {
  height: calc(100% - 60px);
  overflow-y: auto;
  padding: 10.42px;
  box-sizing: border-box;
  display: grid;
  gap: 10.42px;
  align-content: flex-start;
  padding: 14.58px 10.42px 38.19px 10.42px;
  box-sizing: border-box;
}
.row_img {
  width: 69.44px;
  height: 69.44px;
  background: rgba(241, 232, 190, 0);
  border-radius: 6.94px;
  margin-right: 14.58px;
}
.row_middle {
  width: 144.44px;
  height: 49.32px;
  margin-right: 26.74px;
  display: grid;
  align-content: center;
}
.row_name {
  height: 49.32px;
  line-height: 24.66px;
  margin-bottom: 1.03px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 15.97px;
}
.row_btn {
  width: 76.39px;
  height: 34.72px;
  border-radius: 6.94px;
  font-size: 13.19px;
}
.is_disabled {
  opacity: 0.5;
}
.row_status {
  height: 22.93px;
  line-height: 22.93px;
  display: flex;
  align-items: center;
  gap: 6.25px;
  font-size: 14.58px;
  font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  font-weight: 400;
  color: #14c76a;
}
.row_status img {
  width: 14.58px;
  height: 14.58px;
}
div.done_over {
  font-size: 13.19px;
  font-family: Microsoft YaHei, Microsoft YaHei-Regular;
  font-weight: 400;
  text-align: left;
  color: #666666;
}
</style>
